package com.ly.algorithm.DataStructures.search;

/**
 * @Classname InsertValueSearch
 * @Description TODO
 * @Date 2020/4/25 10:46
 * @Author 冷心影翼
 */
public class InsertValueSearch {

    public static void main(String[] args) {
        int[] arr = {1,3,5,7,9,11,15,27,81};
        System.out.println(search(arr, 0, arr.length - 1, 7));
    }

    public static int search(int[] arr, int left, int right, int value) {

        if(left>right ||  value<arr[0] || value>arr[arr.length-1]) {
            return -1;
        }
        int mid = left + (right-left)*(value-arr[left])/(arr[right]-arr[left]);
        if(arr[mid]>value) {
            return search(arr,left,mid,value);
        }else if(arr[mid] == value){
            return mid;
        }else {
            return search(arr,mid+1,right,value);
        }
    }
}
